package per.johnson.net.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by Johnson on 2018/9/23.
 */
public class Server {
    ServerSocket serverSocket;
    public Server() throws IOException {
        serverSocket = new ServerSocket(80);
    }
    public void listen() throws IOException {
        Socket client = serverSocket.accept();
        InputStream is = client.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        System.out.println(bufferedReader2String(br));
    }
    private String bufferedReader2String(BufferedReader reader) throws IOException {
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            sb.append(line).append(System.lineSeparator());
        }
        return sb.toString();
    }

    public static void main(String[] args) throws IOException {
        Server server = new Server();
        server.listen();
    }


}
